#!/usr/local/bin/node

var express = require("express");
var fs = require("fs");

var app = express(),
    port = 8080;

var cat = {categories: []};


app.get("/rest/categories", function(request, response) {
    fs.readdir('../images', function(err, files) {
        cat.categories = files;
        response.send(cat);
    });
});

app.get('/rest/img/:type', function (req, res) {
    var folder = req.params.type,
        json = {};

    json.category = folder;

    fs.readdir('../images/' + folder, function(err, files) {
        json.files = files;
        res.send(json);
    });

});


app.configure(function() {
    app.use(express.bodyParser());
});


app.post('/rest/post', function(req, res){
    console.log(req.param("name"));
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('thanks');
});

app.listen(port);
console.log("Node server running on port " + port);